package com.lgk.controller;

import com.github.pagehelper.PageInfo;
import com.lgk.domain.User;
import com.lgk.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class UtilController {

    @Autowired
    private UserService userService;

    /**
     * 用户登录
     */
    @RequestMapping("/users/to/logic")
    public String toLogic(User user, Model model){
        boolean b =  userService.getByUserNameAndPassword(user);
        if(b) {
            model.addAttribute("username", user.getName());
            return "home";
        }else {
            model.addAttribute("msg", "登录失败，请检查！");
            return "redirect:../../index" + ".jsp";
        }
    }

    @RequestMapping("to/home/{username}")
    public String toHome(Model model, @PathVariable("username")String username){
        model.addAttribute("username", username);
        return "home";
    }



}
